package com.aw.guiguzi.module.manager._files.presenters

import com.aw.baselib.base.AwCommonPresenter
import com.aw.baselib.net.callback.AwApiCallback
import com.aw.guiguzi.bean.BasePageRspBean
import com.aw.guiguzi.bean.FileItemBean
import com.aw.guiguzi.module.manager._files.views.FileListView
import com.aw.guiguzi.net.observers.NetObCommon

/**
 * @author : hzw
 */
class FileListPresent(private val mView: FileListView.View) : AwCommonPresenter(),
    FileListView.Presenter {
    override fun getFileList(pageIndex: Int) {
        addIOSubscription<BasePageRspBean<FileItemBean>>(
            NetObCommon.getFileList(pageIndex),
            object : AwApiCallback<BasePageRspBean<FileItemBean>>(mView, true, true) {
                override fun onSuccess(result: BasePageRspBean<FileItemBean>) {
                    mView.getFileListSuccess(result.total, result?.list ?: emptyList())
                }

                override fun onFail(code: Int, msg: String) {
                    super.onFail(code, msg)
                    mView.showMsg(msg)
                    mView.getFileListFail(code, msg)
                }
            })
    }

    override fun delFile(id: String?) {
        addIOSubscription(
            NetObCommon.delFile(id),
            object : AwApiCallback<Boolean>(mView, true, true) {
                override fun onSuccess(result: Boolean) {
                    mView.delFileSuccess()
                }

                override fun onFail(code: Int, msg: String) {
                    super.onFail(code, msg)
                    mView.showMsg(msg)
                }
            })
    }
}